Contents
Full Software
Trial Software
News Plus
Online
Hands On
Essential Files
Contact Details
Help Section
Contents Page



JBuilder Tutorial
To become productive with Borland's Java development system, JBuilder, on this month's SuperCD, follow these three simple steps with our very own Java guru, Huw Collingbourne...

Step One: Take the Tour
Before trying to build your own applications, it's a good idea to familiarise yourself with the essential features of JBuilder by working your way through its Welcome project. This project appears automatically when you load JBuilder for the first time. If necessary, you can reload the project by following these steps:

  • From the File menu select Open/Create.
  • In the File Open dialog set the File Type filter to 'Java Projects'.
  • Navigate to the JBuilder\Samples\Welcome directory.
  • Double-click the Welcome.jpr project to load it.
    Once the Welcome project is loaded, you can click the right-facing arrows at the top of the View pane to scroll through a number of screens. These provide an overview of the JBuilder user interface and design tools. In the final screen of the tour you will see some hyperlinks to additional tutorials. We suggest that you study these later on. First, let's spend a few minutes getting to know the JBuilder environment better...

    Step Two: Explore the User Interface
    The JBuilder user interface combines the design, debugging and editing tools within a single, multi-page window. Let's see these in action.

  • Select File menu, New...

    A multi-page dialog will now pop up. This can be used to help create a variety of forms, objects, menus and other items. You might want to click the tabs to see what's available. We'll create an application.

  • Make sure the first page in the dialog, labelled 'New', is visible.
  • Click the 'Application' icon.
  • Click OK.
  • Name the package 'TestApp' and the class 'TestClass'. Check the Generate Header Comments option. When you've done this, the fields in the dialog should look like this:



  • Click Next.
  • In the next dialog, enter the title 'My Test Frame' and check off the Generate Menu Bar and Centre Frame On Screen options as follows:



  • Click Finish.

    At this point, JBuilder will automatically generate a form and Java source code based on your selected options. Make sure that the Project and Source tabs are selected. You will see the code of the file, Frame1 .Java, in the editor. It has a block of comments at the top (since you selected Generate Header Comments) and you will see that the code includes a Menu bar:

    MenuBar menuBar1 = new MenuBar();

  • To run the application, press [SHIFT][F9].

    You should see that when the application executes, its form is centred in the screen. This is due to the fact that you selected the 'Centre Frame' option when setting up the project.

    To close the application, select its File menu and click Exit.

    Step Three: Designing and Coding
    Now let's add a couple of components to the form.

  • Click the Design tab beneath the code editor pane in order to switch to the visual design page.
  • On the Controls page of the palette (at the top of the screen), click the Button.
  • Now click the blank form in the design page of the editor in order to drop a button on to it.
  • In a similar way, drop a TextField (the last-but-one control on the palette) on to the form.
  • Resize the button and text field on the form using the mouse.
  • Select the button on the form.
  • In the Property Inspector, double-click the 'label' property and enter the label 'Click Me'.
    Your form should look like this:



    We will now program an event-handler that will place text into the text field when the button is clicked.

  • Make sure the button is selected on the form.
  • Switch to the Events page in the Properties Inspector.
  • Double-click the actionPerformed event.
    This should place your cursor in the code editor. JBuilder will have created this empty event-handler:

    void buttonControl1_actionPerformed(ActionEvent e) {

    }

  • Edit this as follows, making sure to use capital letters where shown, since Java is a case-sensitive language:

    void buttonControl1_actionPerformed(ActionEvent e) {
    textFieldControl1.setText("Hello world!");
    }

  • Press [SHIFT][F9] to run the application.

    Now when you click the button, the text "Hello world" should appear in the field.

    Although this is a trivial application, it introduces most of the essential features of the JBuilder environment including its editor, component palette and form designer.

    It also illustrates how to adjust properties and code event-handlers. Try adapting this application by adding some extra buttons and altering other properties such as 'font' and 'foreground'.

    Once you feel at home with the JBuilder interface, we suggest that you reload the Welcome.jpr project, navigate to the final page and then follow the links to the additional on-line tutorials.





  •  
     
    Contents | Top | Help